var a = require("../../../../@babel/runtime/helpers/interopRequireDefault")(require("../../../../@babel/runtime/regenerator")), t = require("../../../../@babel/runtime/helpers/asyncToGenerator"), e = require("../../../../mycomponent/payKeyboard/PayKeyboardAsync.js"), n = getApp(), o = require("../../../../utils/themeSkin/skinBehavior");

Page({
    behaviors: [ o ],
    data: {
        mailLanguage: {},
        language: "",
        withdrawToWechat: 0,
        withdrawToAlipay: 0,
        withdrawToManual: 0,
        supplier: "",
        balance: 0,
        service_money: 0,
        withdrawType: {},
        info_form: {
            balance_money: ""
        },
        pay_type: "",
        eupshow: !1,
        popupVisible: !1,
        hxShow: !1,
        action: "",
        msg: "",
        notice: "",
        balanceLang: "余额",
        member_id: "",
        converge_pay: !1,
        show2: !1,
        show3: !1,
        withList: [],
        checkObj: {},
        actual_amount: "",
        poundageHj: "",
        cost_money: "",
        poundage_name: "",
        worker_withdraw_wechat: !1,
        worker_withdraw_alipay: !1,
        worker_withdraw_bank: !1,
        worker_withdraw: {},
        payKeyboardShow: !1,
        need_password: !1,
        has_password: !1,
        manual_name: "",
        eplus_withdraw_bank: !1,
        eplus_withdraw_is_auth: !1,
        show: !1,
        list: [],
        silver_point: !1,
        bank_card_status: !1,
        support_code: !1,
        support_center_withdraw: !1,
        support_center_withdraw_name: "帮扶中心",
        support_code_url: ""
    },
    onLoad: function(a) {
        a.supplier && this.setData({
            supplier: a.supplier
        }), a.member_id && this.setData({
            member_id: a.member_id
        }), this.customizeIncome();
        try {
            var t = JSON.parse(wx.getStorageSync("mailLanguage"));
            t && (this.setData({
                mailLanguage: t,
                manual_name: t.income.name_of_withdrawal + t.income.manual_withdrawal
            }), wx.setNavigationBarTitle({
                title: this.data.mailLanguage.income && this.data.mailLanguage.income.name_of_withdrawal ? this.data.mailLanguage.income.name_of_withdrawal : "提现"
            }));
        } catch (a) {
            console.log(a);
        }
        try {
            var e = wx.getStorageSync("balance");
            e && this.setData({
                balanceLang: e
            });
        } catch (a) {}
    },
    customizeIncome: function() {
        try {
            var a = wx.getStorageSync("mailLanguage");
            if (a) {
                var t = JSON.parse(a);
                this.setData({
                    poundage_name: t.income.poundage_name
                });
            }
        } catch (a) {}
    },
    onReady: function() {
        var a = wx.getStorageSync("langIndex");
        this.setData({
            language: a.en
        });
    },
    onShow: function() {
        "supplier" === this.data.supplier ? this.getData2() : this.getData();
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    getData2: function() {
        var a = this, t = n.getNetAddresss("plugin.supplier.frontend.withdraw.index");
        t += "&member_id=" + this.data.member_id, n._getNetWork({
            url: t,
            success: function(t) {
                var e = t.data;
                1 == e.result ? (a.setData({
                    balance: e.data.cost_money,
                    service_money: e.data.service_money,
                    withdrawType: e.data.type,
                    service_type: e.data.service_type
                }), wx.setNavigationBarColor({
                    frontColor: "#ffffff",
                    backgroundColor: a.data.themeBaseColor,
                    animation: {
                        duration: 400,
                        timingFunc: "easeIn"
                    }
                })) : wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                });
            },
            fail: function(a) {
                console.log(a);
            }
        });
    },
    onConfirm: function(a) {
        var t = this;
        if (console.log(a, "ddddddddd"), a.detail.radio) wx.showModal({
            content: "请选择银行卡",
            showCancel: !1
        }); else {
            var e = {
                withdraw_type: "13",
                withdraw_money: this.data.info_form.balance_money,
                bank_card_no: a.detail.radio
            }, o = n.getNetAddresss("finance.balance-withdraw.withdraw");
            n._getNetWork({
                url: o,
                data: e,
                success: function(a) {
                    var e = a.data;
                    1 == e.result ? wx.showModal({
                        content: e.msg,
                        showCancel: !1,
                        success: function() {
                            t.setData({
                                "info_form.balance_money": "",
                                show: !1
                            });
                        }
                    }) : n.tips(e.msg);
                },
                fail: function(a) {
                    console.log(a);
                }
            });
        }
    },
    getBankList: function() {
        var a = this, t = n.getNetAddresss("plugin.eplus-pay.frontend.card.bindCardList");
        n._getNetWork({
            url: t,
            success: function(t) {
                var e = t.data;
                1 == e.result ? (a.setData({
                    list: e.data
                }), a.getCartWith("eplus")) : n.tips(e.msg);
            },
            fail: function(a) {
                console.log(a);
            }
        });
    },
    towithdrawalHj: function(a) {
        var t = this, e = a.target.dataset.index;
        if (this.setData({
            pay_type: e
        }), 5 != this.data.pay_type) this.towithdrawal(e); else {
            var o = n.getNetAddresss("plugin.converge_pay.frontend.controllers.converge-pay-bank-card.get-bank-card");
            n._getNetWork({
                url: o,
                success: function(a) {
                    var e = a.data;
                    if (1 == e.result) {
                        t.setData({
                            checkObj: e.data
                        });
                        var n = e.data.bankName + "(" + e.data.receiverAccountNoEnc.substring(e.data.receiverAccountNoEnc.length - 4) + ")";
                        return t.setData({
                            show2: !0,
                            "checkObj.bankName": n
                        }), t.getwithList(), void t.getCartWith();
                    }
                    return -1 == e.data.status && wx.navigateTo({
                        url: "/packageA/others/HJinfo/bankCardInformation/bankCardInformation"
                    }), void wx.showToast({
                        title: e.msg,
                        icon: "none"
                    });
                },
                fail: function(a) {
                    console.log(a.msg);
                }
            });
        }
    },
    all: function() {
        this.setData({
            "info_form.balance_money": this.data.balance
        });
    },
    getData: function() {
        var a = this, t = n.getNetAddresss("finance.balance-withdraw.page");
        n._getNetWork({
            url: t,
            success: function(t) {
                var e = t.data;
                1 == e.result ? (a.setData({
                    worker_withdraw_wechat: e.data.worker_withdraw_wechat,
                    worker_withdraw_alipay: e.data.worker_withdraw_alipay,
                    worker_withdraw_bank: e.data.worker_withdraw_bank,
                    worker_withdraw: e.data.extra_data.worker_withdraw,
                    balance: e.data.balance,
                    withdrawToAlipay: e.data.alipay,
                    withdrawToWechat: e.data.wechat,
                    withdrawToManual: e.data.manual,
                    poundage: e.data.poundage,
                    eupshow: e.data.eup_pay,
                    converge_pay: e.data.converge_pay,
                    need_password: e.data.need_password,
                    has_password: e.data.has_password,
                    eplus_withdraw_bank: !!e.data.eplus_withdraw_bank && e.data.eplus_withdraw_bank,
                    eplus_withdraw_is_auth: !!e.data.extra_data.eplus_withdraw && e.data.extra_data.eplus_withdraw.is_auth,
                    silver_point: e.data.silver_point,
                    bank_card_status: e.data.bank_card_status,
                    support_center_withdraw: !!e.data.support_center_withdraw && e.data.support_center_withdraw,
                    support_center_withdraw_name: e.data.support_center_withdraw_name ? e.data.support_center_withdraw_name : "帮扶中心"
                }), wx.setNavigationBarColor({
                    frontColor: "#ffffff",
                    backgroundColor: a.data.themeBaseColor,
                    animation: {
                        duration: 400,
                        timingFunc: "easeIn"
                    }
                })) : wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                });
            },
            fail: function(a) {
                console.log(a);
            }
        });
    },
    payKeyboardComplete: function(a) {
        e.payKeyboardAsync.complete(a.detail);
    },
    getPayKeyboardPassword: function() {
        return this.setData({
            show2: !1,
            show3: !1,
            payKeyboardShow: !0
        }), new Promise(function(a, t) {
            e.payKeyboardAsync.addCompleteFn(function(t) {
                a(t);
            });
        });
    },
    payKeyboardClose: function() {
        this.setData({
            payKeyboardShow: !1
        });
    },
    confirm: function(a) {
        var t = a.currentTarget.dataset.num, e = a.currentTarget.dataset.text;
        if ("worker_withdraw_wechat" == e && 0 == this.data.worker_withdraw.wechat_is_register || "worker_withdraw_bank" == e && 0 == this.data.worker_withdraw.bank_is_register) "worker_withdraw_wechat" == e ? wx.navigateTo({
            url: "/packageI/worker/index/index?register_type_Id=2"
        }) : wx.navigateTo({
            url: "/packageI/worker/index/index?register_type_Id=1"
        }); else switch (this.setData({
            pay_type: t
        }), this.data.pay_type) {
          case "3":
            this.manualVerify(this.data.pay_type);
            break;

          case "4":
            this.checkEup(this.data.pay_type);
            break;

          case "5":
            this.checkHx(this.data.pay_type);
            break;

          case "6":
            if ("" == this.data.info_form.balance_money) return void wx.showToast({
                title: "请输入提现金额",
                icon: "none"
            });
            this.checkHJ(this.data.pay_type);
            break;

          case "15":
            this.support_center();
            break;

          default:
            this.confirmPost(this.data.pay_type);
        }
    },
    support_code_close: function() {
        this.setData({
            support_code: !1
        });
    },
    support_center: function() {
        var a = this;
        n._postNetWork({
            url: n.getNetAddresss("plugin.support-center.frontend.withdraw.get-write-off-code"),
            data: {
                withdraw_money: this.data.info_form.balance_money,
                withdraw_type: "15"
            },
            success: function(t) {
                var e = t.data;
                1 == e.result ? a.setData({
                    support_code_url: e.data.url,
                    support_code: !0
                }) : n.tips(e.msg);
            },
            fail: function(a) {
                console.log(a.msg);
            }
        });
    },
    checkOut: function(a) {
        var t = a.target.dataset.item || a.currentTarget.dataset.item;
        t.check = !t.check;
        var e = this.data.withList;
        e.map(function(a) {
            a.id == t.id ? a.check = t.check : a.check = !1;
        }), 1 == t.check && this.setData({
            show3: !1,
            show2: !0,
            checkObj: t,
            withList: e
        });
    },
    getToTitle: function() {
        var a = this, t = n.getNetAddresss("plugin.converge_pay.frontend.controllers.converge-pay-bank-card.set-bank-card");
        n._postNetWork({
            url: t,
            data: {
                set: this.data.checkObj
            },
            success: function(t) {
                var e = t.data;
                1 == e.result ? a.confirmPost(a.data.pay_type) : wx.showToast({
                    title: e.msg,
                    icon: "none",
                    duration: 1500
                });
            },
            fail: function(a) {
                console.log(a);
            }
        });
    },
    withGotiem: function() {
        console.log(this.data.checkObj, "选中的项"), this.getToTitle();
    },
    backGo: function() {
        this.setData({
            show2: !0,
            show3: !1
        });
    },
    backTap: function() {
        this.setData({
            show2: !1,
            show3: !1
        });
    },
    gotoList: function() {
        this.setData({
            show2: !1,
            show3: !0
        });
    },
    confirmPost: function(e) {
        var o = this;
        return t(a.default.mark(function t() {
            var s, i, r;
            return a.default.wrap(function(a) {
                for (;;) switch (a.prev = a.next) {
                  case 0:
                    if (s = o, !(parseFloat(o.data.info_form.balance_money) > parseFloat(o.data.balance))) {
                        a.next = 4;
                        break;
                    }
                    return wx.showToast({
                        icon: "none",
                        title: "提现金额不可大于您的" + s.data.balanceLang,
                        duration: 1500
                    }), a.abrupt("return");

                  case 4:
                    if (!(null == o.data.info_form.balance_money || o.data.info_form.balance_money <= 0 || 0 == o.data.info_form.balance_money)) {
                        a.next = 7;
                        break;
                    }
                    return wx.showToast({
                        icon: "none",
                        title: "提现金额不可低于0",
                        duration: 1500
                    }), a.abrupt("return");

                  case 7:
                    if (1 != o.data.need_password || 0 != o.data.has_password) {
                        a.next = 13;
                        break;
                    }
                    return a.next = 10, n.confirm("请先设置支付密码");

                  case 10:
                    return a.sent && wx.navigateTo({
                        url: "/packageA/member/set_balance_password/set_balance_password"
                    }), a.abrupt("return");

                  case 13:
                    if (13 != e) {
                        a.next = 21;
                        break;
                    }
                    if (0 != o.data.eplus_withdraw_is_auth) {
                        a.next = 19;
                        break;
                    }
                    return wx.showModal({
                        content: "请先完成认证",
                        showCancel: !1,
                        success: function(a) {
                            wx.navigateTo({
                                url: "/packageF/others/wisdom/wisdomBindTask/wisdomBindTask"
                            });
                        }
                    }), a.abrupt("return");

                  case 19:
                    return o.getBankList(), a.abrupt("return");

                  case 21:
                    if (14 != e) {
                        a.next = 25;
                        break;
                    }
                    if (o.data.bank_card_status) {
                        a.next = 25;
                        break;
                    }
                    return wx.showModal({
                        content: "该会员未添加默认银行卡",
                        showCancel: !1,
                        success: function(a) {
                            a.confirm && wx.navigateTo({
                                url: "/packageA/member/memberBank/memberBank"
                            });
                        }
                    }), a.abrupt("return");

                  case 25:
                    if (i = n.getNetAddresss("finance.balance-withdraw.withdraw"), i += "&withdraw_type=" + e, 
                    i += "&withdraw_money=" + o.data.info_form.balance_money, 1 != o.data.need_password) {
                        a.next = 33;
                        break;
                    }
                    return a.next = 31, o.getPayKeyboardPassword();

                  case 31:
                    r = a.sent, i += "&password=" + r;

                  case 33:
                    if (!o.isLocks) {
                        a.next = 35;
                        break;
                    }
                    return a.abrupt("return");

                  case 35:
                    o.isLocks = !0, n._getNetWork({
                        url: i,
                        success: function(a) {
                            o.isLocks = !1;
                            var t = a.data;
                            1 == t.result ? (s.setData({
                                show2: !1
                            }), wx.showModal({
                                title: "提示",
                                content: t.msg,
                                showCancel: !1,
                                success: function(a) {
                                    a.confirm && wx.navigateBack({
                                        delta: 1
                                    });
                                }
                            })) : wx.showToast({
                                icon: "none",
                                title: t.msg,
                                duration: 1500
                            });
                        },
                        fail: function(a) {
                            this.isLocks = !1, console.log(a);
                        }
                    });

                  case 37:
                  case "end":
                    return a.stop();
                }
            }, t);
        }))();
    },
    manualVerify: function(a) {
        var t = this, e = this;
        if (parseFloat(this.data.info_form.balance_money) > parseFloat(this.data.balance)) wx.showToast({
            icon: "none",
            title: "提现金额不可大于您的" + e.data.balanceLang,
            duration: 1500
        }); else if (null == this.data.info_form.balance_money || this.data.info_form.balance_money <= 0 || 0 == this.data.info_form.balance_money) wx.showToast({
            icon: "none",
            title: "提现金额不可低于0",
            duration: 1500
        }); else if (!this.isLocks) {
            this.isLocks = !0;
            var o = n.getNetAddresss("finance.balance-withdraw.is-can-submit");
            n._postNetWork({
                url: o,
                showToastIn: !1,
                success: function(n) {
                    t.isLocks = !1;
                    var o = n;
                    1 == o.data.result ? o.data.data.status ? e.confirmPost(a) : e.setManualInfo(a, o.data.data.manual_type) : wx.showToast({
                        icon: "none",
                        title: o.msg,
                        duration: 1500
                    });
                },
                fail: function(a) {
                    this.isLocks = !1, console.log(a.msg);
                }
            });
        }
    },
    setManualInfo: function(a, t) {
        var e = "", n = "";
        switch (t) {
          case "bank":
            e = "请先填写银行卡信息", n = "memberBank";
            break;

          case "wechat":
            e = "请先填写微信信息", n = "info";
            break;

          case "alipay":
            e = "请先填写支付宝信息", n = "info";
        }
        wx.showModal({
            title: "提示",
            content: e,
            success: function(a) {
                a.confirm ? "memberBank" == n ? wx.navigateTo({
                    url: "/packageA/member/memberBank/memberBank"
                }) : "info" == n && wx.navigateTo({
                    url: "/packageA/member/info/info"
                }) : a.cancel && console.log("用户点击取消");
            }
        });
    },
    checkEup: function(a) {
        var t = this, e = this;
        if (!this.isLocks) {
            this.isLocks = !0;
            var o = n.getNetAddresss("plugin.eup-pay.api.account.pi-account");
            n._postNetWork({
                url: o,
                showToastIn: !1,
                data: _url,
                success: function(n) {
                    t.isLocks = !1;
                    var o = n;
                    1 == o.result ? 1 == o.data.bool && e.confirmPost(a) : 0 == o.result && wx.showModal({
                        title: "提示",
                        content: msg,
                        success: function(a) {
                            a.confirm ? wx.navigateTo({
                                url: "/packageA/member/info/info"
                            }) : a.cancel && console.log("用户点击取消");
                        }
                    });
                },
                fail: function(a) {
                    this.isLocks = !1, console.log(a.msg);
                }
            });
        }
    },
    _initHxpay: function() {
        this.setData({
            action: "",
            msg: "",
            notice: ""
        });
    },
    getwithList: function() {
        var a = this, t = n.getNetAddresss("plugin.converge_pay.frontend.controllers.converge-pay-bank-card.get-bank-card-list");
        n._getNetWork({
            url: t,
            success: function(t) {
                var e = t.data;
                1 == e.result ? (0 == e.data.length && (wx.showToast({
                    title: "请先去添加银行卡",
                    icon: "none"
                }), wx.navigateTo({
                    url: "/packageA/others/HJinfo/bankCardInformation/bankCardInformation"
                })), e.data.map(function(a) {
                    a.check = !1, "" != a.receiverAccountNoEnc && null != a.receiverAccountNoEnc && (a.bankName += "(" + a.receiverAccountNoEnc.substring(a.receiverAccountNoEnc.length - 4) + ")");
                }), a.setData({
                    withList: e.data
                })) : (wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                }), setTimeout(function() {}, 2e3));
            },
            fail: function(a) {
                console.log(a);
            }
        });
    },
    show1CloseBtn: function() {
        this.setData({
            show2: !1,
            show3: !1,
            show: !1
        });
    },
    getCartWith: function(a) {
        var t = this, e = "";
        "suppier" == a ? e = n.getNetAddresss("plugin.supplier.frontend.withdraw.converge-withdraw") : (e = n.getNetAddresss("finance.balance-withdraw.converge-withdraw"), 
        e += "&withdraw_money=" + this.data.info_form.balance_money), n._getNetWork({
            url: e,
            success: function(e) {
                var n = e.data;
                1 == n.result ? (t.setData({
                    poundageHj: n.data.poundage,
                    actual_amount: n.data.actual_amount,
                    cost_money: n.data.cost_money
                }), "eplus" == a && t.setData({
                    show: !0
                })) : wx.showModal({
                    title: "提示",
                    content: n.msg
                });
            },
            fail: function(a) {
                console.log(a.msg);
            }
        });
    },
    checkHJ: function(a) {
        var t = this;
        if (!this.isLocks) {
            this.isLocks = !0;
            var e = n.getNetAddresss("plugin.converge_pay.frontend.controllers.converge-pay-bank-card.get-bank-card");
            n._getNetWork({
                url: e,
                success: function(a) {
                    t.isLocks = !1;
                    var e = a.data;
                    if (1 == e.result) {
                        t.setData({
                            checkObj: e.data
                        });
                        var n = e.data.bankName + "(" + e.data.receiverAccountNoEnc.substring(e.data.receiverAccountNoEnc.length - 4) + ")";
                        t.setData({
                            show2: !0,
                            "checkObj.bankName": n
                        }), t.getwithList(), t.getCartWith();
                    } else -1 == e.data.status && wx.navigateTo({
                        url: "/packageA/others/HJinfo/bankCardInformation/bankCardInformation"
                    }), wx.showModal({
                        title: "提示",
                        content: e.msg
                    });
                },
                fail: function(a) {
                    this.isLocks = !1, console.log(a.msg);
                }
            });
        }
    },
    submitbrank: function() {
        n._postNetWork({
            url: this.data.action,
            showToastIn: !1,
            data: {
                ipsRequest: this.data.msg
            },
            success: function(a) {
                wx.navigateBack({
                    delta: 1
                });
            },
            fail: function(a) {}
        });
    },
    towithdrawal: function(a) {
        var t = this;
        this.setData({
            pay_type: a.currentTarget.dataset.index
        });
        if (null == this.data.balance || this.data.balance <= 0 || 0 == this.data.balance) wx.showToast({
            icon: "none",
            title: "提现金额不可低于0",
            duration: 1500
        }); else {
            var e = n.getNetAddresss("plugin.supplier.frontend.withdraw.withdraw");
            e += "&apply_type=" + this.data.pay_type, e += "&member_id=" + this.data.member_id, 
            n._getNetWork({
                url: e,
                success: function(a) {
                    var e = a.data;
                    1 == e.result ? (t.getData2(), wx.showToast({
                        title: e.msg,
                        icon: "none",
                        duration: 1500,
                        success: function() {
                            setTimeout(function() {
                                wx.navigateBack({
                                    delta: 1
                                });
                            }, 1500);
                        }
                    })) : wx.showToast({
                        icon: "none",
                        title: e.msg,
                        duration: 1500
                    });
                },
                fail: function(a) {
                    console.log(a);
                }
            });
        }
    },
    balanceMoneyinp: function(a) {
        var t = a.detail.value;
        this.setData({
            "info_form.balance_money": t
        });
    }
});